<?php
class arcController extends Controller{
    public static function _right(){
        return array(
            array('广告管理'),
            array('广告添加','add,add_'),
            array('广告列表','mylist'),
            array('广告编辑','mod,mod_'),
            array('广告删除','del'),
            array('静态生成','html,html_'),
            array('批量操作','bit_op'),
        );
    }
	public function __construct(){
		parent::__construct();
		
	}
	public function s(){
		return array('arc');
	}
	public function index(){
	
	}
	//输出并更新文章点击次数
	public function update_arc_hits(){
		$id=intval($_GET['id']);
		echo $this->s_0->update_arc_hits($id);
	}
	public function dig_test(){
		include($this->viewer_dir.'arc/dig.php');
	}
	//文章的顶踩功能 ajax获取顶踩数据
	public function dig_data(){
		$data=array();
		$id=intval($_POST['id']);
		$data=$this->s_0->dig_data($id);
		if(!$data) exit;
		//echo json_encode($data);
		include($this->viewer_dir.'arc/dig_tpl.inc.php');
		exit;
	}
	//好评
	public function dig_good(){
		$data=array();
		$id=intval($_POST['id']);
		$data=$this->s_0->dig_good($id);
		if(!$data) exit;
		//echo json_encode($data);
		include($this->viewer_dir.'arc/dig_tpl.inc.php');
		exit;
	}
	//差评
	public function dig_bad(){
		$data=array();
		$id=intval($_POST['id']);
		$data=$this->s_0->dig_bad($id);
		if(!$data) exit;
		//echo json_encode($data);
		include($this->viewer_dir.'arc/dig_tpl.inc.php');
		exit;
	}
	//挑错
	public function pick_error(){
		$id=intval($_GET['id']);
		if($id<=0) exit('id error!');
		$r=$this->s_0->pick_error($id);
		if(!$r) exit('id error!');
		$type_arr=$this->s_0->pick_error_type();
		
		$widget=load_service('a_widget',P_SVC);
		
		include($this->viewer_dir.'arc/pick_error.php');
	}
	public function pick_error_(){
		if($_POST){
			if($_POST['captcha']!=$_SESSION['code']){
				alert('验证码不正确！');
				back();
			}
			$r=$this->s_0->pick_error_($_POST);
			if($r[0]){
				alert('提交成功！');
			}else{
				alert($r[1]);
			}
			back();
        }
	}
	//文章推荐
	public function recommend(){
		$id=intval($_GET['id']);
		if($id<=0) exit('id error!');
		$r=$this->s_0->recommend($id);
		if(!$r) exit('id error!');
		$widget=load_service('a_widget',P_SVC);
		
		include($this->viewer_dir.'arc/recommend.php');
	}
	
	public function recommend_(){
		if($_POST){
			if($_POST['captcha']!=$_SESSION['code']){
				alert('验证码不正确！');
				back();
			}
			if(!preg_match("/^[0-9a-zA-Z]+@(([0-9a-zA-Z]+)[.])+[a-z]{2,4}$/i",$_POST['email'])){
				alert('邮箱格式不正确！');
				back();
			}
			if(!$_POST['msg']){
				alert('留言内容不能为空！');
				back();
			}
			$r=$this->s_0->recommend_($_POST);
			if($r[0]){
				alert('发送成功！');
			}else{
				alert('发送失败！');
			}
			back();
        }
	}
	//文章收藏部分
	public function favorite_test(){
		//include($this->viewer_dir.'arc/fav.php');
	}
	public function favorite(){
		$echo=array('code'=>1,'msg'=>'文章收藏成功！');
		$id=intval($_POST['id']);
		if($id<=0){
			$echo['code']=-1;
			$echo['msg']='文章id错误！';
			echo json_encode($echo);
			exit;
		}
		//检查登陆
		if(!isset($_SESSION['MY']['UID']) || intval($_SESSION['MY']['UID'])<=0){
			$echo['code']=-2;
			$echo['msg']='登陆后才可以收藏文章！';
			echo json_encode($echo);
			exit;
		}
		$r=$this->s_0->favorite($id);
		if(!$r){
			$echo['code']=-1;
			$echo['msg']='文章id错误！';
			echo json_encode($echo);
			exit;
		}
		$t=$this->s_0->favorite_($id,$_SESSION['MY']['UID'],array('title'=>$r['title'],'htmlurl'=>$r['htmlurl']));
		if(!$t){
			$echo['code']=-3;
			$echo['msg']='文章收藏失败！';
			echo json_encode($echo);
			exit;
		}
		echo json_encode($echo);
		exit;
	}
	
//
}